import {Request, Response} from "express";
import regionServer from "@src/services/regionServer";
import region from "@src/models/region";

const paths = {
  // 区域id 关联文献
  detail: "/region-detail/:id",
  // 关联文章接口列表，区域id
  relationArticleList: "/relation-article-list/:id",
  // 关联文献列表
  relationLiteratureList: "/relation-literature-list/:id",
};

// 区域详情
const detail = async (req: Request, res: Response) => {
  const {id} = req.params;
  // 字段+1
  await region.increment({visit_num: 1}, {where: {category_id: id}});
  const data: any = await regionServer.detail(id);
  return res.status(data.code).json({
    data,
  });
};

export default {
  paths,
  detail,
};